package com.boss.salary.controller;
import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.salary.entity.ConfigCtrl;
import com.boss.salary.service.IAgencyPersonRestrictService;
import com.boss.salary.service.IConfigCtrlService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestSchema(schemaId = "ConfigCtrlController")
@RestController
@RequestMapping(value = "/ConfigCtrlController")
public class ConfigCtrlController  extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(AgencyPersonRestrictController.class);

    @Autowired
    private IAgencyPersonRestrictService agencyPersonRestrictService;

    @Autowired
    private IConfigCtrlService iConfigCtrlService;


    /**
     * 修改
     *
     * @param
     * @return
     */
    @PostMapping("/updataIsAbleConfigCtrl")
    public ApiResultDTO updataIsAbleConfigCtrl(@RequestHeader("tokenid") String tokenid,
                                              @RequestBody List<ConfigCtrl> configCtrls) {
        try {
            UserDTO userDTO = getUser(tokenid);
            iConfigCtrlService.updataIsAbleConfigCtrl(userDTO.getProvince(),configCtrls);

            return ApiResultDTO.success(null, "修改成功");
        } catch (Exception e) {
            logger.error("修改 单位信息表发生异常", e);
            return ApiResultDTO.error(ERROR_RSCODE, "修改 单位信息表发生异常");
        }
    }


    /**
     *
     *查询
     * @param tokenid
     * @return
     */
    @GetMapping("/selectConfigCtrl")
    public ApiResultDTO selectConfigCtrl(@RequestHeader("tokenid") String tokenid) {
        try {
            UserDTO userDTO = getUser(tokenid);
            List<ConfigCtrl> selectConfigCtrl = iConfigCtrlService.selectConfigCtrl(userDTO.getProvince());
            return ApiResultDTO.success(selectConfigCtrl, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询数据异常");
        }
    }


    /**
     * 是否显示功能支出科目
     */

    @GetMapping("/selectFuncName")
    public ApiResultDTO selectFuncName(@RequestHeader("tokenid") String tokenid) {
        try {
            UserDTO userDTO = getUser(tokenid);
            //PersonImportControl为1显示，为0不显示
            int getFuncName= iConfigCtrlService.selectFuncName(userDTO.getProvince());
            return ApiResultDTO.success(getFuncName, null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询批量新增控制数据异常");
        }
    }


}
